<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
    	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>编辑商品</title>
	    <link rel="stylesheet" href="css/AllStyle.css" />
	    <link rel="stylesheet" href="css/iconfont.css" />
	    <script type="text/javascript" src="js/common.js" ></script>
	    <script type="text/javascript" src="js/companydata.js" ></script>
	    <script type="text/javascript" src="js/data.js" ></script>
	    <script type="text/javascript" src="js/tmpl.js" ></script>
	</head>
	<body>
		<!-- 页头 -->
	    <section>
		    <script type="text/javascript">
		        AllPageHeader()
		    </script>
	    </section>
	    
	    <!-- 页面  -->
	    <section class="AllContent">
	    	<form>
	    		<div class="FormStyle">
	    			<ul>
	    				<li>网点名称：</li>
						<li><input type="text" id="name" name="name" value="" placeholder="网点名称"/></li>
	    				<li>联系人：</li>
        				<li><input type="text" id="link_man" name="link_man" value="" placeholder="联系人"/></li>
        				<li>联系电话：</li>
        				<li><input type="text" id="phone" name="phone" value="" placeholder="联系电话" /></li>
        				<li>省：</li>
        				<li>
							<select  type="text" id="province" name="province"></select>
        				</li>
        				<li>市：</li>
        				<li>
							<select type="text" id="city" name="city" ></select>
        				</li>
        				<li>区：</li>
        				<li>
							<select type="text" id="area" name="area" ></select>
        				</li>
        				<li>街道地址：</li>
        				<li><input type="text" id="address" name="address" value="" placeholder="街道地址"/></li>
        				<li>邮箱：</li>
        				<li><input type="text" id="email" name="email" value="" placeholder="邮箱" /></li>
        				
        				<li>状态：</li>
        				<li>
        					<select name="status" id="status">
                                <option value="正常">正常</option>
                                <option value="关闭">关闭</option>
                            </select>
        				</li>
	    			</ul>
	    			<div class="FormPhoto">
	    				<img id="branch_pic" name="branch_pic" src="images/Photo2.png">
	    				<!--<input type="file" id="file_upload"/>-->
	    				<div class="ImageHosting">空间图片</div>
	    			</div>
	    			<p style="margin:0px 4.5%;font-size:0.83em;color:#999;margin-top:10px;font-family: arial;line-height:23px;">上传图片大小不能超过2M，最佳尺寸为200x200px</p>
	    			
					<input type="text" id="bid" name="bid" value=""  style="display:none"/>
	    			<button class="NextButton" type="button" onclick="savebranch();">保存</button>
	    		</div>
	    	</form>
	    	
	    	<div class="SlidingLayer">
	    		<div style="overflow: hidden;background-color:#fff;">
	    			<span class="ImageHostingTitle">空间图片</span>
	    			<img class="CloseImg" style="width:30px;" src="images/remover.png">
	    		</div>
	    		<ul id="piclist">
	    			
	    		</ul>
	    	</div>
	    </section>
	    
	    <section>
	    	<div class="MaskLayer">
		    	<div class="MaskContent">
		    		<p><img src="images/loading5.gif"></p>
		    		<p>正在添加...</p>
		    	</div>
	    	</div>
	    </section>
		
	</body>
	<script type="text/javascript" src="js/jquery.min.js" ></script>
	<script type="text/javascript" src="js/mui.min.js" ></script>
	<script type="text/javascript" src="js/jsAddress.js" ></script>
	<script type="text/javascript">
	    mui.init();
		$('.AllHeader li:eq(1)').text('编辑网点')
		
		$(function () {
			$("#file_upload").change(function() {
				var $file = $(this);
				var fileObj = $file[0];
				var windowURL = window.URL || window.webkitURL;
				var dataURL;
				var $img = $("#branch_pic");
				 
				if(fileObj && fileObj.files && fileObj.files[0]){
				dataURL = windowURL.createObjectURL(fileObj.files[0]);
				$img.attr('src',dataURL);
				}else{
				dataURL = $file.val();
				var imgObj = document.getElementById("branch_pic");
				imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
				imgObj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;
				 
				}
			});
			
	        var bid = $_GET['bid'];
	        $.ajax({
	            type: "post",
	            url: getServerUrl() + "/Open/Company/catbranch",
	            dataType: 'json',
	            data: 'access_token=' + getToken()+'&bid='+bid,
	            success: function (json) {
	                if(json.result == 1){
	                     var branch = json.branchlist[0];
	                     $("#bid").val(bid);
	                     $("#name").val(branch.name);
	                     $("#link_man").val(branch.link_man);
	                     $("#cat_name").val(branch.cat_name);
	                     $("#phone").val(branch.phone);
	                     $("#province").val(branch.province);
	                     $("#city").val(branch.city);
	                     $("#area").val(branch.area);
	                     $("#address").val(branch.address);
	                     $("#email").val(branch.email);
	                     $("#status").val(branch.status);
	                     $("#baiduxy").val(branch.baiduxy);
						 $('#branch_pic').attr("src",branch.branch_pic);
	                     $("#googlexy").val(branch.googlexy);
	                     addressInit('province', 'city', 'area',branch.province,branch.city,branch.area);
	                	 getpic('全部',1);
	                }else{
	                    alertMessage(json.error_description);
	                }
	
	            },
	            error: function () {
	                alertMessage("请检查网络连接！");
	            }
	        });
	    });
	
	    function onDeviceReady() {
	        //document.addEventListener("backbutton", onBackKeyDown, false);
	    }
	    function onBackKeyDown() {
	        //openUrl("/Desktop/index");
	    }
	
	    function savebranch() {
	        var bid = $("#bid").val();
	        var name = $("#name").val();
	        var link_man = $("#link_man").val();
	        var phone = $("#phone").val();
	        var province = $("#province").val();
	        var city = $("#city").val();
	        var area = $("#area").val();
	        var address = $("#address").val();
	        var email = $("#email").val();
	        var status = $("#status").val();
	        var baiduxy = $("#baiduxy").val();
	        var googlexy = $("#googlexy").val();
	        var branch_pic = $('#branch_pic').attr("src");
	        if (empty(bid)) {
	            alertMessage("网点id不能为空！");
	            return;
	        }
	        if (empty(name)) {
	            alertMessage("网点名称不能为空！");
	            return;
	        }
	       var datas = {access_token:getToken(),bid:bid,name:name,link_man:link_man,phone:phone,province:province,city:city,area:area,address:address,email:email,status:status,baiduxy:baiduxy,googlexy:googlexy,branch_pic:branch_pic};
	
	        $.ajax({
	             type: "post",
	             url: getServerUrl() + "/Open/Company/editbranch",
	             dataType: 'json',
	             data: datas,
	             success: function (json) {
	                 if(json.result == "1") {
	                    openUrl("ScreentoneList.html");
	                 }else{
	                    alertMessage("编辑网点失败:[" + json.error_description + "]");
	                 }
	             }
	         });
	    }
	
	    function ajaxFileUpload()
	    {
	        $("#loading")
	                .ajaxStart(function () {
	                    $(this).show();
	                })
	                .ajaxComplete(function () {
	                    $(this).hide();
	                });
	
	        $.ajaxFileUpload
	                (
	                        {
	                            url: '/Open/Common/uploadpic',
	                            secureuri: false,
	                            fileElementId: 'file',
	                            dataType: 'json',
	                            data: {access_token:getToken(),ajax: '1', groupname: '产品图片', updFileName: 'file'},
	                            success: function (data)
	                            {
	                                //alert(data);
	                                if (data.data) {
	                                    //$('#logoimg').attr('src','/Public/upload/pics/'+data.data);
	                                    //$('#pic').val('/Public/upload/pics/'+data.data);
	                                    $('#logoimg').attr('src', data.data);
	                                    $('#pic_url').val(data.data);
	                                }
	                                //alert(data.data);
	                            },
	                            error: function (data, status, e)
	                            {
	                                //alert(data);
	                            }
	                        }
	                )
	
	        return false;
	    }
	    
	</script>
</html>
